package util
{
	import flash.display.DisplayObject;
	import flash.display.Sprite;
	
	public class Container extends Sprite
	{
		private var _list:Array = [];
		private var _space:int = 10;
		public function Container()
		{
			super();
		}
		
		public function get space():int
		{
			return _space;
		}

		public function set space(value:int):void
		{
			_space = value;
		}

		public function addItem(view:DisplayObject):void{
			addChild(view);
			_list.push(view);
			
			resize();
		}
		
		private function resize():void
		{
			var num:int = _list.length;
			var temp:Number = 0;
			for(var i:int=0; i<num; i++){
				temp +=  _list[i].width;
			}
			temp = width - temp;
			temp = temp-(num-1)*_space;
			
			var startX:Number = temp/2;
			
			for(var j:int=0; j<num; j++){
				if (j!=0){
					_list[j].x = startX+_list[j-1].width + _space;
				}
				else{
					_list[j].x = startX;
				}
			}
		}
	}
}